package com.hongyan.dao;

import com.hongyan.bean.Student;
import com.hongyan.util.JDBCUtils;

import java.util.List;

public class S_infoDao {
    public static Object[][] findS_infoByName(String name) {

        String sql = "select * from s_info where s_name like '%"+name+"%' order by s_name asc;";
        List<Student> query = null;
        query = JDBCUtils.query(sql, Student.class);
        Object[][] S_infos = new Object[query.size()][];
        for (int i = 0; i < query.size(); i++) {
            S_infos[i] = query.get(i).toArray();
        }
        return S_infos;


    }
    public static Object[][] getS_infoListBySql(String sql) {

        List<Student> query = null;
        query = JDBCUtils.query(sql, Student.class);
        Object[][] S_info = new Object[query.size()][];
        for (int i = 0; i < query.size(); i++) {
            S_info[i] = query.get(i).toArray();
        }
        return S_info;

    }

    public static void deleteS_info(String id) {
        String sql = "DELETE FROM S_info WHERE s_id = ?;";
        JDBCUtils.update(sql, id);
    }

    public static Student findS_infoById(String sId) {
        String sql = "select * from S_info where s_id = " + sId + "; ";
        List<Student> query = null;
        query = JDBCUtils.query(sql, Student.class);
        Student sys = query.get(0);;
        return sys;
    }

    public static int insertStudent(Student s) {

        String sql = "INSERT INTO S_info  VALUES (?,?,?, ?,?,?,?);";
        return JDBCUtils.update(sql, s.getS_id(),s.getS_name(),s.getC_id(),s.getSex(),s.getContact(),s.getCollege(),s.getPassword());
    }

    public static int updateStudent(Student s) {

        String sql = "UPDATE S_info SET s_name = ?,c_id = ?,sex = ?,contact = ?,college = ?,password = ? WHERE s_id = ?;";
        return JDBCUtils.update(sql,s.getS_name(),s.getC_id(),s.getSex(),s.getContact(),s.getCollege(),s.getPassword(),s.getS_id());
    }
}


